package com.huilink.webmail.util.client.widgets;

import com.google.gwt.user.client.ui.ChangeListener;
import com.google.gwt.user.client.ui.TextBox;

public class TextInputPanel extends InputPanel {

	private TextBox textBox;

	public TextInputPanel(String key, String value, String description){
		setDescription(description);
		setOriginValue(value);
		textBox = new TextBox();
		textBox.setName(key);
		setValue(value);
		setInputWidget(textBox);
		textBox.setStyleName("input-panel-textbox");
		initInputPanel();
	}
	
	public void setValue(String value) {
		if(value!=null)textBox.setText(value);
		else textBox.setText("");
	}
	
	public int getLength(){
		return textBox.getMaxLength();
	}
	
	public void setLength(String length){
		int temp = Integer.parseInt(length);
		textBox.setMaxLength(temp);
	}
	
	public void setWidth(String value){
		textBox.setWidth(value);
	}

	public void addChangeListener(ChangeListener listener) {
		textBox.addChangeListener(listener);
	}

	public String getValue() {
		return textBox.getText();
	}
	
	public void reset() {
		setValue(getOriginValue());
	}
	
}
